﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Core.Services;
using System.Web.Mvc;
using MvcEngine.Mvc.Extensions;
using MvcEngine.Mvc.Constraints;
using MvcEngine.Mvc;
using MvcEngine.Core;
using MvcEngine.Core.Registry;
using MvcEngine.Mvc.Filters;
using MvcEngine.Core.Account;
using MvcEngine.Mvc.ModelBinders;
using MvcEngine.Mvc.Models;

namespace MvcEngine.Mvc.Services
{
    public class LoginControlService : ControlServiceBase
    {
        public override void RegisterStarterSiteRoutes(AreaRegistrationContext context)
        {
            context.MapModuleRoute(
                "StarterSite_LoginControl",
                "{pageName}/Account/LogIn",
                new { actionName = "LogOnControl" },
                new string[] { "MvcEngine.Mvc.StarterSite.Controllers" }
            );

            context.MapModuleRoute(
                "StarterSite_LogoutControl",
                "{pageName}/Account/LogOut",
                new { actionName = "LogOutControl" },
                new string[] { "MvcEngine.Mvc.StarterSite.Controllers" }
            );
        }

        public override void RegisterModelBinders(ModelBinderDictionary binders)
        {
            binders[typeof(LoginViewModel)] = new LoginModelBinder();
        }

        public override Type GetControllerType()
        {
            return typeof(MvcEngine.Mvc.StarterSite.Controllers.AccountController);
        }

        public override string GetDefaultAction()
        {
            return "LogOnControl";
        }
    }
}
